/*
 * File:         ThingTest.java
 * Author:       Robert Bittle <guywithnose@gmail.com>
 */
package foxtrotbravo.tests;

import static org.junit.Assert.*;

import org.junit.Test;

import tests.AppEngineTest;

import twss.Thing;

/**
 * The Class ThingTest.
 */
@SuppressWarnings("static-method")
public class ThingTest extends AppEngineTest {

	/**
	 * Tests the getID method.
	 */
	@Test
	public void testGetID() {
		Thing thing = new Thing(4);
		assertEquals(4, thing.getID());
	}

	/**
	 * Tests the getName method.
	 */
	@Test
	public void testGetName() {
		Thing thing = new Thing();
		thing.setName("abc");
		assertEquals("abc", thing.getName());
	}

	/**
	 * Tests the dataBase method.
	 */
    @Test
	public void testDataBase() {
		Thing thing = new Thing();
		thing.setName("testName");
		thing.save();//Save the object
		Thing thing2 = new Thing(thing.getID());//Load the object
		assertEquals("testName", thing2.getName());//Verify the object is equal
		thing2.setName("newTestName");//Update the name
		thing2.save();//Save the object
		Thing thing3 = new Thing(thing.getID());//Load the object again
		assertEquals("newTestName", thing3.getName());//Verify the object is updated
		thing.delete();//Delete the object
		Thing thing4 = new Thing(thing.getID());
		assertEquals(null, thing4.getName());//Verify the object is deleted
	}

	/**
	 * Tests the toJSONString method.
	 */
	@Test
	public void testToJSONString() {
		Thing thing = new Thing(3);
		thing.setName("testName");
		assertEquals("{\"id\":3,\"name\":\"testName\"}", thing.toJSONString());			
	}

}
